/*
 * Copyright (C), 2020, 安徽艾伦家居饰品有限公司
 * FileName: Oauth客户端配置
 * Author:   Allen
 * Date:     2020/8/17
 * Description: Oauth客户端配置
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.haoyu.auth.client.manager;

import com.haoyu.auth.client.dto.TokenDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * Oauth客户端配置
 *
 * @author Allen
 * @date 2020/8/17
 */
@FeignClient(value = "haoyu-auth-server")
public interface OauthServerClient {

    /**
     * 从marge cloud auth server获取token
     *
     * @param basicAuth clientId和clientSecret的base64加密
     * @param username 用户名
     * @param password 密码
     * @param grantType 授权方式默认使用password
     * @return TokenDTO 返回token数据
     */
    @RequestMapping(method = RequestMethod.POST, value = "/uaa/oauth/token",
        consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    TokenDTO createToken(@RequestHeader("Authorization") String basicAuth, @RequestParam("username") String username,
                   @RequestParam("password") String password, @RequestParam("grant_type") String grantType);

    /**
     * 从marge cloud auth server刷新token
     *
     * @param basicAuth clientId和clientSecret的base64加密
     * @param grantType 授权方式默认使用refresh_token
     * @param refreshToken 刷新Token值
     * @return TokenDTO 返回新的token数据
     */
    @RequestMapping(method = RequestMethod.POST, value = "/uaa/oauth/token",
        consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    TokenDTO refreshToken(@RequestHeader("Authorization") String basicAuth,
                          @RequestParam("grant_type") String grantType,
                          @RequestParam("refresh_token") String refreshToken);

    /**
     * 退出登录
     * @param accessToken accessToken
     * @return 是否成功标识
     */
    @GetMapping(value = "/uaa/oauth/logout", produces = MediaType.APPLICATION_JSON_VALUE)
    Boolean revokeToken(@RequestParam(value = "accessToken") String accessToken);
}